{% extends 'user_layout.html' %}

{% block lk %}
    {% load static %}
    <title>收货信息</title>
    <link rel="stylesheet" href="{% static 'plugins/bootstrap-3.4.1/css/bootstrap.min.css' %}">
{% endblock %}

{% block content_user %}
    <h3 class="common_title2">收货地址</h3>
    <div class="site_con">
        <dl>
            <dt>默认地址：</dt>
            <dd>{{ address_data_default.address }} （{{ address_data_default.receiver }} 收） {{ address_data_default.phone }}</dd>
        </dl>
    </div>
    <div class="site_con">

            <dl>
                <dt>其他地址：</dt>
                {% for item in  address_data_not_default%}
                    <dd>{{ item.address }} （{{ item.receiver }} 收） {{ item.phone }}
                    <span style="float: right">
                        <input uid="{{ item.id }}" class="btn btn-danger btn-xs btn-default"  type="button" value="设为默认" style="background-color: #4cae4c;border-color: white;">
                        <input uid="{{ item.id }}" class="btn btn-danger btn-xs btn-delete"  type="button" value="删除">
                    </span>
                    </dd>

                {% endfor %}
            </dl>
    </div>
    <div>
     <a class="btn btn-success" href="http://127.0.0.1:8000/add/address/">
                <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>
                添加地址
     </a>
    </div>




{% endblock %}


{% block js %}
    <script type="text/javascript">

        $('.btn-default').click(function (){

                var uid = $(this).attr('uid');

                $.ajax({
                    url: "/default/address/",
                    type: "GET",
                    data: {
                        uid: uid,
                    },
                    dataType: 'JSON',
                    success: function (res){
                        if(res.status){
                            location.reload();
                        }
                    }

                })
            });

        $('.btn-delete').click(function (){

           var uid = $(this).attr('uid');
            $.ajax({
                url: "/delete/address/",
                type: 'GET',
                data: {
                    uid: uid,
                },
                dataType: 'JSON',
                    success: function (res){
                        if(res.status){
                            location.reload();
                        }
                    }

            })

        })




    </script>

{% endblock %}